/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.model.Command.EditCommand;

import javax.swing.JOptionPane;
import simplemetrosystem.control.ElementManager;
import simplemetrosystem.model.Command.Command;
import simplemetrosystem.model.Element.MetroEdge;
import simplemetrosystem.model.charlanguage.NameMap;

/**
 *
 * @author Eric Qian
 */
public class AddEdgeCommand implements Command {

    /**
     * 
     * @param stA
     * @param stB
     * @param line
     */
    public AddEdgeCommand(String stA, String stB, String line) {
        this.stA = stA;
        this.stB = stB;
        this.line = line;
        nameMap = NameMap.getInstance();
        success = false;
    }

    public void execute() {
        ElementManager elementManager = ElementManager.getInstance();
        if (elementManager.addEdge(stA, stB, line, 0, 0, 0)) {
            success = true;
            edge = elementManager.findEdge(stA, stB, line);
        } else {
            JOptionPane.showMessageDialog(null, nameMap.getName("Fail to add edge"),
                    nameMap.getName("WARNING"), JOptionPane.WARNING_MESSAGE);
        }
    }

    public void undo() {
        if (success) {
            ElementManager.getInstance().removeEdge(edge);
        }
    }
    private boolean success;
    private NameMap nameMap;
    private MetroEdge edge;
    private String stA;
    private String stB;
    private String line;
}
